﻿#region
using System;
using System.Linq;
using System.Windows.Forms;
using ComicsDownloader.Engine;
using ComicsDownloader.Properties;

#endregion

namespace ComicsDownloader.Forms
{
    public partial class MainForm : RootForm
    {
        public MainForm()
        {
            InitializeComponent();
        }

        protected override void OnShown(EventArgs e)
        {
            base.OnShown(e);

            if (DesignMode || RunTimeChecker.IsRunTime == false)
                return;

            bdsList.DataSource = CartoonRepository.Instance.Cartoons.OrderBy(x => x.Name);
        }

        private void lsbList_DoubleClick(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(Settings.Default.DownloadRoot))
                tsiOption.PerformClick();

            if (string.IsNullOrEmpty(Settings.Default.DownloadRoot))
            {
                MessageBox.Show("먼저 저장위치를 설정하세요.");
                return;
            }

            Cartoon cartoon = bdsList.Current as Cartoon;

            if (cartoon == null)
                return;

            using (var form = new DownloadForm(cartoon))
            {
                form.ShowDialog();
            }
        }

        private void tsiOption_Click(object sender, EventArgs e)
        {
            using (var form = new OptionForm())
            {
                form.ShowDialog();
            }
        }
    }
}